Color = {}
local colorsmeta = {}
function Color.new(r,g,b)
  local info = {}
  info.r = r
  info.g = g
  info.b = b
  setmetatable(info, colorsmeta)
  return info
end

Particle = {}
local particlemeta = {}
function Particle.new(x,y)
  local info = {}
  info.x = x
  info.y = y
  info.dx = math.random(50)-25
  info.dy = math.random(50)-25
  info.color = Color.new(192+math.random(64),64+math.random(64),0 )
  info.life = 0.8
  --setmetatable(info, particlemeta )
  return info
end

function DrawParticles()
  local deadParticles = {}
  for i,v in pairs(particles) do
    setcolor( v.color.r * v.life, v.color.g * v.life , v.color.b * v.life )
    alphaparticle(v.x,v.y)
    --drawsph( v.x, v.y, 5 )
    
    v.x = v.x + v.dx * deltatime
    v.y = v.y + v.dy * deltatime
    
    v.life = v.life - deltatime
    if( v.life <= 0.0) then
      table.insert(deadParticles, i)
    end  
  end
  
  for i=1, #deadParticles do
    k = deadParticles[i]
    table.remove(particles,k)
  end
end

function circleExplosion(x,y,radi)
  for k = 1, 100 do
    local cx = math.cos( k*2*math.pi / 99 )*radi
    local cy = math.sin( k*2*math.pi / 99 )*radi
    table.insert(particles,Particle.new( cx+x + math.random(-10.0, 10.0), cy+y + math.random(-10.0, 10.0) ))
  end 
end